<template>
  <div>
    <a-modal :bodyStyle="{ padding: '20px' }" title="新增设备" :visible="show" @ok="submit" @cancel="close" :width="460"
      centered>
      <a-form-model :model="queryParams" :rules="rules" :labelCol="{ style: 'width: 78px' }" ref="form" class="ant-advanced-form" >
        <a-form-model-item label="设备编号" prop="deviceNo">
          <a-input v-model="queryParams.deviceNo" style="width:280px" placeholder="请输入设备编号"></a-input>
        </a-form-model-item>
      </a-form-model>
    </a-modal>
  </div>
</template>

<script>
import { addHardwareDevice } from '@/services/car'
import { deviceNoRules } from '@/utils/validate'
export default {
  data () {
    return {
      show: false,
      queryParams: {},
      rules: {
        deviceNo: [
          { required: true, message: '请输入设备编号', trigger: 'blur' }
          // { validator: deviceNoRules }
        ]
      }
    }
  },
  methods: {
    onInitial (row) {
      console.log(row)
      // this.params = row
      // this.queryParams = {
      //   memberId: row.id,
      //   phoneOld: row.phone
      // }
      this.show = true
    },
    submit () {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.onAdd()
        }
      })
    },
    async onAdd () {
      const res = await addHardwareDevice(this.queryParams.deviceNo)
      if (res.isSuccess) {
        this.$message.newFun('新增设备成功', 'success', 2)
        this.close()
      } else {
        this.$message.newFun(res.msg, 'error', 2)
      }
    },
    close () {
      this.show = false
      this.queryParams = {}
      this.$emit('modelClose')
    }
  }
}
</script>

<style>

</style>
